package com.hotel.controller;

import com.hotel.entity.Room;
import com.hotel.response.MessageUtils;
import com.hotel.response.RestResponse;
import com.hotel.service.RoomService;
import com.hotel.service.RoomTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 夏智力
 * @FileName RoomController
 * @date 2021/6/22 18:53
 * @Software: IntelliJ IDEA
 */
@RestController
public class RoomController {

    @Autowired
    private RoomService roomService;

    @RequestMapping(path = "/room/list", method = RequestMethod.GET)
    public RestResponse getRoomList() {
        List<Room> rooms = roomService.selectRoom();
        return MessageUtils.success(rooms);
    }

    //  根据类型id查询对应类型的空房
    @RequestMapping(path = "/room/list/type", method = RequestMethod.GET)
    public RestResponse getRoomListByTypeId(int typeId) {
        List<Room> rooms = roomService.selectRoomByTypeId(typeId);
        return MessageUtils.success(rooms);
    }

    // 前台锁定房间
    @RequestMapping(path = "/room/occupy", method = RequestMethod.POST)
    public void occupyRoom(Room room) {
        room.setStatus(1);
        roomService.updateRoom(room);
    }

    // 退房
    @RequestMapping(path = "/room/checkout", method = RequestMethod.POST)
    public void CheckOutRoom(Room room) {
        room.setStatus(0);
        // 解锁房间
        roomService.updateRoom(room);
    }

    // 添加房间
    @RequestMapping(path = "/room/add", method = RequestMethod.POST)
    public void addRoom(Room room) {
        roomService.addRoom(room);
    }

    // 修改房间
    @RequestMapping(path = "/room/update", method = RequestMethod.POST)
    public void updateRoom(Room room) {

        roomService.updateRoom(room);

    }

    // 删除房间
    @RequestMapping(path = "/room/delete", method = RequestMethod.DELETE)
    public void deleteRoom(int id) {
        roomService.deleteRoom(id);
    }

}
